﻿\subsubsection{memset()}
\myindex{\CStandardLibrary!memset()}

\myparagraph{\Example \#1}

\lstinputlisting[caption=32 bytes,style=customc]{\CURPATH/str_mem/memset_32.c}

\myindex{x86!\Instructions!MOV}
Many compilers don't generate a call to memset() for short blocks, but rather insert a pack of \MOV{}s:


\lstinputlisting[caption=\Optimizing GCC 4.9.1 x64,style=customasmx86]{\CURPATH/str_mem/memset_32_GCC491_x64_O3.s}

\myindex{Unrolled loop}
By the way, that remind us of unrolled loops: 
\myref{ARM_unrolled_loops}.

\myparagraph{\Example \#2}

\lstinputlisting[caption=67 bytes,style=customc]{\CURPATH/str_mem/memset_67.c}

When the block size is not a multiple of 4 or 8, the compilers can behave differently.


\myindex{x86!\Instructions!MOV}
For instance, MSVC 2012 continues to insert \TT{MOV}s:


\lstinputlisting[caption=\Optimizing MSVC 2012 x64,style=customasmx86]{\CURPATH/str_mem/memset_67_MSVC2012_x64_Ox.asm}

\myindex{x86!\Instructions!STOSQ}
\dots while GCC uses \TT{REP STOSQ}, concluding that this would be shorter than a pack of \TT{MOV}s:


\lstinputlisting[caption=\Optimizing GCC 4.9.1 x64,style=customasmx86]{\CURPATH/str_mem/memset_67_GCC491_x64_O3.s}
